package com.ruoyi.hr.controller.hr.salaryadmin.salarychangecorrection;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.hr.domain.Authority;
import com.ruoyi.hr.service.AuthorityService;
import com.ruoyi.hr.service.salaryadmin.salarychangecorrection.SalaryChangeCorrectionService;
import com.ruoyi.hr.util.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 薪资变动纠错
 */
@Controller
@RequestMapping("/SalaryChangeCorrection/SalaryChangeCorrection")
public class SalaryChangeCorrectionController extends BaseController {

    @Autowired
    AuthorityService authorityService;

    @Autowired
    SalaryChangeCorrectionService salaryChangeCorrectionService;

    private String prefix = "hr/salaryadmin/salarychangecorrection";

    /**
     * 跳转初始化页面
     */
    @GetMapping()
    public String SalaryChangeCorrection() {
        return prefix + "/salaryChangeCorrection";
    }

    @RequestMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map map) {
        Authority authority = authorityService.findAuthorAndIsAdmin();
        List<Map<String, Object>> list = salaryChangeCorrectionService.list(map, authority);
        return getDataTable(list);
    }

    @RequestMapping("/findDataHistory")
    @ResponseBody
    public TableDataInfo findDataHistory(@RequestParam Map map) {
        Authority authority = authorityService.findAuthorAndIsAdmin();
        startPage();
        List<Map<String, Object>> list = salaryChangeCorrectionService.findDataHistory(map, authority);
        return getDataTable(list);
    }

    /**
     * 跳转初始化页面历史
     */
    @GetMapping("/salaryChangeCorrectionHistory")
    public String salaryChangeCorrectionHistory() {
        return prefix + "/salaryChangeCorrectionHistory";
    }


    @GetMapping("/addEmp")
    public String addEmp(@RequestParam Map map, ModelMap mmap) {
        mmap.put("map", map);
        return prefix + "/addEmp";
    }

    @RequestMapping("/changeAdd2")
    @ResponseBody
    public BaseResult changeAdd2(String allid) {
        return salaryChangeCorrectionService.changeAdd2(allid);
    }

    @RequestMapping("/changeStart")
    @ResponseBody
    public BaseResult changeStart(String allid) {
        return salaryChangeCorrectionService.changeStart(allid);
    }

    @RequestMapping("/deleteEmp")
    @ResponseBody
    public BaseResult deleteEmp(String allid) {
        return salaryChangeCorrectionService.deleteEmp(allid);
    }


    @PostMapping("/updateSalary")
    @ResponseBody
    public int updateSalary(@RequestParam Map map) {
        //项目
        String[] array = map.get("benefitTypeAndXl").toString().split("@@@");
        String stdId = array[1];
        map.put("stdId", stdId);
        return salaryChangeCorrectionService.updateSalary(map);
    }


    /**
     * 数据确认,取消确认,执行
     */
    @PostMapping("/threeProcedure")
    @ResponseBody
    public BaseResult threeProcedure(String allId, String type) {
        return salaryChangeCorrectionService.threeProcedure(allId, type);
    }
}
